textview: Mind the lateral windows when setting handles/popovers positions
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 17 Mar 2014 16:42:07 +0000 (17:42 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 17 Mar 2014 17:26:41 +0000 (18:26 +0100)
If a textview had lateral windows that might displace the text window, the
handles and popovers would appear displaced. Those lateral windows aren't
affected by RTL/LTR settings, so just checking for left/top is ok here.

gtk/gtktextview.c

index d71e9f493d42343c7616a3d0b271c8960e3d82f4..6dffa38e772f95949677d53bfe7cab5afbbe1b8a 100644 (file)
@@ -4587,6 +4587,32 @@ emit_event_on_tags (GtkWidget   *widget,
   return retval;
 }
 
+static void
+_text_window_to_widget_coords (GtkTextView *text_view,
+                               gint        *x,
+                               gint        *y)
+{
+  GtkTextViewPrivate *priv = text_view->priv;
+
+  if (priv->top_window)
+    (*y) += priv->top_window->requisition.height;
+  if (priv->left_window)
+    (*x) += priv->left_window->requisition.width;
+}
+
+static void
+_widget_to_text_window_coords (GtkTextView *text_view,
+                               gint        *x,
+                               gint        *y)
+{
+  GtkTextViewPrivate *priv = text_view->priv;
+
+  if (priv->top_window)
+    (*y) -= priv->top_window->requisition.height;
+  if (priv->left_window)
+    (*x) -= priv->left_window->requisition.width;
+}
+
 static void
 gtk_text_view_set_handle_position (GtkTextView           *text_view,
                                    GtkTextIter           *iter,
@@ -4617,6 +4643,8 @@ gtk_text_view_set_handle_position (GtkTextView           *text_view,
 
       rect.x = CLAMP (x, 0, SCREEN_WIDTH (text_view));
       rect.y = CLAMP (y, 0, SCREEN_HEIGHT (text_view));
+      _text_window_to_widget_coords (text_view, &rect.x, &rect.y);
+
       _gtk_text_handle_set_position (priv->text_handle, pos, &rect);
     }
 }
@@ -4639,6 +4667,7 @@ gtk_text_view_show_magnifier (GtkTextView *text_view,
   rect.x = x;
   rect.y = y;
   rect.width = rect.height = 1;
+  _text_window_to_widget_coords (text_view, &rect.x, &rect.y);
 
   _gtk_magnifier_set_coords (GTK_MAGNIFIER (priv->magnifier), x, y);
   gtk_popover_set_pointing_to (GTK_POPOVER (priv->magnifier_popover),
@@ -4665,6 +4694,8 @@ gtk_text_view_handle_dragged (GtkTextHandle         *handle,
   buffer = get_buffer (text_view);
   mode = _gtk_text_handle_get_mode (handle);
 
+  _widget_to_text_window_coords (text_view, &x, &y);
+
   gtk_text_view_selection_bubble_popup_unset (text_view);
   gtk_text_layout_get_iter_at_pixel (priv->layout, &iter,
                                      x + priv->xoffset,
@@ -9008,6 +9039,8 @@ bubble_targets_received (GtkClipboard     *clipboard,
   rect.x -= priv->xoffset;
   rect.y -= priv->yoffset;
 
+  _text_window_to_widget_coords (text_view, &rect.x, &rect.y);
+
   gtk_popover_set_pointing_to (GTK_POPOVER (priv->selection_bubble), &rect);
   gtk_widget_show (priv->selection_bubble);